<template>
    <div class="qingwu">
        <div class="admin_table_page_title">
            <a-button type="primary" @click="onload">
                刷新
            </a-button>
            <a-button type="primary"  @click="timeData" :loading="spinShow">
                获取实时数据
            </a-button>
        </div>
        <div class="unline underm"></div>
        <div class="admin_form">
            <a-form-model :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }">
                <a-form-model-item label="电表编码">{{eleData.code}}</a-form-model-item>
                <a-form-model-item label="抄表时间">{{info.devTime}}</a-form-model-item>
                <a-form-model-item label="余额">{{userInfo.electricity_bill_balance}}</a-form-model-item>
                <a-form-model-item label="总电能" >{{info.electricity}}</a-form-model-item>
                <a-form-model-item label="电流" >{{info.current}}</a-form-model-item>
                <a-form-model-item label="电压" >{{info.voltage}}</a-form-model-item>
                <a-form-model-item label="总功率" >{{info.power}}</a-form-model-item>
                <a-form-model :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }" v-if="eleData.cate==2">
                    <a-form-model-item label="A相功率" >{{info.Pa}}</a-form-model-item>
                    <a-form-model-item label="B相功率" >{{info.Pb}}</a-form-model-item>
                    <a-form-model-item label="C相功率" >{{info.Pc}}</a-form-model-item>
                    <a-form-model-item label="A相电压" >{{info.Va}}</a-form-model-item>
                    <a-form-model-item label="B相电压" >{{info.Vb}}</a-form-model-item>
                    <a-form-model-item label="C相电压" >{{info.Vc}}</a-form-model-item>
                    <a-form-model-item label="A相电流" >{{info.Ia}}</a-form-model-item>
                    <a-form-model-item label="B相电流" >{{info.Ib}}</a-form-model-item>
                    <a-form-model-item label="C相电流" >{{info.Ic}}</a-form-model-item>
                </a-form-model>

                <a-form-model-item label="总功率因数" >{{info.powerFactor}}</a-form-model-item>
                <a-form-model-item label="A相功率因数" v-if="eleData.cate==2">{{info.PFa}}</a-form-model-item>
                <a-form-model-item label="B相功率因数" v-if="eleData.cate==2">{{info.PFb}}</a-form-model-item>
                <a-form-model-item label="C相功率因数" v-if="eleData.cate==2">{{info.PFc}}</a-form-model-item>
                <a-form-model-item label="拉合闸状态" >{{eleData.close}}</a-form-model-item>
                <a-form-model-item label="保电状态" >{{eleData.protect}}</a-form-model-item>
            </a-form-model>
        </div>

    </div>

</template>

<script>
export default {
    props:['params'],
    data(){
        return {
            info:{
            },
            eleData:{
            },
            userInfo:{
                electricity_bill_balance:0
            },
            spinShow:false
        }
    },
    methods:{
        get_info(){
            this.$get(this.$api.electricTimeData+'/'+this.params.id+'/'+this.params.community+'/'+this.params.tableAddress+'/'+this.params.code).then(res=>{
                console.log(res)
                let data = res.data.data
                this.info = data;
                this.eleData = data.eleData;
                this.params.collect_id = data.eleData.collect_id
                if(data.userInf){
                    this.userInfo = data.userInfo;
                }

                this.$forceUpdate();
            })
        },
        onload(){
            this.spinShow = false
            this.get_info();
        },
        timeData(){
            this.$get(this.$api.realTimeData,this.params).then(res=>{
                this.spinShow = true
                if(res.code==200){
                    setTimeout(()=>{
                        this.onload();
                    },5000)
                    setTimeout(()=>{
                        this.$message.success('ok')
                    },6000)
                }else {
                    return this.$message.error('获取失败')
                }
            })
        }
    },
    created() {
        this.onload();
    },
}
</script>
